package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.EmployeeDAO;
import cn.edu.scau.cmi.hombio.dao.TaskDAO;
import cn.edu.scau.cmi.hombio.dao.TaskManageDAO;

import cn.edu.scau.cmi.hombio.domain.Employee;
import cn.edu.scau.cmi.hombio.domain.Task;
import cn.edu.scau.cmi.hombio.domain.TaskManage;

import cn.edu.scau.cmi.hombio.service.TaskManageService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for TaskManage entities
 * 
 */

@Controller("TaskManageRestController")

public class TaskManageRestController {

	/**
	 * DAO injected by Spring that manages Employee entities
	 * 
	 */
	@Autowired
	private EmployeeDAO employeeDAO;

	/**
	 * DAO injected by Spring that manages Task entities
	 * 
	 */
	@Autowired
	private TaskDAO taskDAO;

	/**
	 * DAO injected by Spring that manages TaskManage entities
	 * 
	 */
	@Autowired
	private TaskManageDAO taskManageDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for TaskManage entities
	 * 
	 */
	@Autowired
	private TaskManageService taskManageService;

	/**
	 * Save an existing Task entity
	 * 
	 */
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/task", method = RequestMethod.PUT)
	@ResponseBody
	public Task saveTaskManageTask(@PathVariable Integer taskmanage_id, @RequestBody Task task) {
		taskManageService.saveTaskManageTask(taskmanage_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* View an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/employee/{employee_id}", method = RequestMethod.GET)
	@ResponseBody
	public Employee loadTaskManageEmployee(@PathVariable Integer taskmanage_id, @PathVariable Integer related_employee_id) {
		Employee employee = employeeDAO.findEmployeeByPrimaryKey(related_employee_id, -1, -1);

		return employee;
	}

	/**
	* Create a new Task entity
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/task", method = RequestMethod.POST)
	@ResponseBody
	public Task newTaskManageTask(@PathVariable Integer taskmanage_id, @RequestBody Task task) {
		taskManageService.saveTaskManageTask(taskmanage_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* View an existing Task entity
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/task/{task_id}", method = RequestMethod.GET)
	@ResponseBody
	public Task loadTaskManageTask(@PathVariable Integer taskmanage_id, @PathVariable Integer related_task_id) {
		Task task = taskDAO.findTaskByPrimaryKey(related_task_id, -1, -1);

		return task;
	}

	/**
	* Save an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/employee", method = RequestMethod.PUT)
	@ResponseBody
	public Employee saveTaskManageEmployee(@PathVariable Integer taskmanage_id, @RequestBody Employee employee) {
		taskManageService.saveTaskManageEmployee(taskmanage_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Get Task entity by TaskManage
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/task", method = RequestMethod.GET)
	@ResponseBody
	public Task getTaskManageTask(@PathVariable Integer taskmanage_id) {
		return taskManageDAO.findTaskManageByPrimaryKey(taskmanage_id).getTask();
	}

	/**
	* Delete an existing Task entity
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/task/{task_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteTaskManageTask(@PathVariable Integer taskmanage_id, @PathVariable Integer related_task_id) {
		taskManageService.deleteTaskManageTask(taskmanage_id, related_task_id);
	}

	/**
	* Select an existing TaskManage entity
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}", method = RequestMethod.GET)
	@ResponseBody
	public TaskManage loadTaskManage(@PathVariable Integer taskmanage_id) {
		return taskManageDAO.findTaskManageByPrimaryKey(taskmanage_id);
	}

	/**
	* Show all TaskManage entities
	* 
	*/
	@RequestMapping(value = "/TaskManage", method = RequestMethod.GET)
	@ResponseBody
	public List<TaskManage> listTaskManages() {
		return new java.util.ArrayList<TaskManage>(taskManageService.loadTaskManages());
	}

	/**
	* Create a new TaskManage entity
	* 
	*/
	@RequestMapping(value = "/TaskManage", method = RequestMethod.POST)
	@ResponseBody
	public TaskManage newTaskManage(@RequestBody TaskManage taskmanage) {
		taskManageService.saveTaskManage(taskmanage);
		return taskManageDAO.findTaskManageByPrimaryKey(taskmanage.getId());
	}

	/**
	* Save an existing TaskManage entity
	* 
	*/
	@RequestMapping(value = "/TaskManage", method = RequestMethod.PUT)
	@ResponseBody
	public TaskManage saveTaskManage(@RequestBody TaskManage taskmanage) {
		taskManageService.saveTaskManage(taskmanage);
		return taskManageDAO.findTaskManageByPrimaryKey(taskmanage.getId());
	}

	/**
	* Delete an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/employee/{employee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteTaskManageEmployee(@PathVariable Integer taskmanage_id, @PathVariable Integer related_employee_id) {
		taskManageService.deleteTaskManageEmployee(taskmanage_id, related_employee_id);
	}

	/**
	* Create a new Employee entity
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/employee", method = RequestMethod.POST)
	@ResponseBody
	public Employee newTaskManageEmployee(@PathVariable Integer taskmanage_id, @RequestBody Employee employee) {
		taskManageService.saveTaskManageEmployee(taskmanage_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Get Employee entity by TaskManage
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}/employee", method = RequestMethod.GET)
	@ResponseBody
	public Employee getTaskManageEmployee(@PathVariable Integer taskmanage_id) {
		return taskManageDAO.findTaskManageByPrimaryKey(taskmanage_id).getEmployee();
	}

	/**
	* Delete an existing TaskManage entity
	* 
	*/
	@RequestMapping(value = "/TaskManage/{taskmanage_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteTaskManage(@PathVariable Integer taskmanage_id) {
		TaskManage taskmanage = taskManageDAO.findTaskManageByPrimaryKey(taskmanage_id);
		taskManageService.deleteTaskManage(taskmanage);
	}
}